{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "outputs": [],
   "source": [
    "# 特征选择：低方差特征过滤\n",
    "# 随便读取以前一些csv文件，通过fit.transform把一些无用的特征过滤掉\n",
    "\n",
    "import pandas as pd\n",
    "from sklearn.feature_selection import VarianceThreshold\n"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-12-21T13:15:12.353254500Z",
     "start_time": "2023-12-21T13:15:05.892617100Z"
    }
   },
   "id": "a16f5fbd959ef090"
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "outputs": [],
   "source": [
    "data = pd.read_csv(\"D://data//bidding//tdz_bsr_score_result.csv\")"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-12-21T13:29:12.823976900Z",
     "start_time": "2023-12-21T13:29:12.725903800Z"
    }
   },
   "id": "630f469af095f02a"
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "outputs": [
    {
     "data": {
      "text/plain": "(9525, 24)"
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.shape "
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-12-21T13:29:27.934434900Z",
     "start_time": "2023-12-21T13:29:27.895176400Z"
    }
   },
   "id": "867757471f0a783d"
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\Administrator\\AppData\\Local\\Programs\\Python\\Python312\\Lib\\site-packages\\sklearn\\feature_selection\\_variance_threshold.py:112: RuntimeWarning: Degrees of freedom <= 0 for slice.\n",
      "  self.variances_ = np.nanvar(X, axis=0)\n"
     ]
    },
    {
     "data": {
      "text/plain": "      unobjective_score  business_score  technology_score  ave_score  \\\n0                   NaN            14.8             35.00      49.80   \n1                   NaN             0.0              0.00       0.00   \n2                   NaN             0.0              0.00       0.00   \n3                   NaN            14.0             49.80      63.80   \n4                   NaN             0.0              0.00       0.00   \n...                 ...             ...               ...        ...   \n9520                NaN            10.0             49.60      59.60   \n9521                NaN             4.0             35.46      39.46   \n9522                NaN             0.0              0.00       0.00   \n9523                NaN            30.0             36.00      66.00   \n9524                NaN             7.0             58.80      65.80   \n\n      price_score  totle_score  ranking  \n0           30.00        79.80        1  \n1       -11530.52    -11530.52       75  \n2        -7274.37     -7274.37      107  \n3           14.24        78.04        1  \n4       -58673.21    -58673.21      126  \n...           ...          ...      ...  \n9520        30.00        89.60        1  \n9521        26.39        65.85        3  \n9522    -33061.64    -33061.64      169  \n9523        28.70        94.70        2  \n9524        29.96        95.76        1  \n\n[9525 rows x 7 columns]",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>unobjective_score</th>\n      <th>business_score</th>\n      <th>technology_score</th>\n      <th>ave_score</th>\n      <th>price_score</th>\n      <th>totle_score</th>\n      <th>ranking</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>NaN</td>\n      <td>14.8</td>\n      <td>35.00</td>\n      <td>49.80</td>\n      <td>30.00</td>\n      <td>79.80</td>\n      <td>1</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>NaN</td>\n      <td>0.0</td>\n      <td>0.00</td>\n      <td>0.00</td>\n      <td>-11530.52</td>\n      <td>-11530.52</td>\n      <td>75</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>NaN</td>\n      <td>0.0</td>\n      <td>0.00</td>\n      <td>0.00</td>\n      <td>-7274.37</td>\n      <td>-7274.37</td>\n      <td>107</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>NaN</td>\n      <td>14.0</td>\n      <td>49.80</td>\n      <td>63.80</td>\n      <td>14.24</td>\n      <td>78.04</td>\n      <td>1</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>NaN</td>\n      <td>0.0</td>\n      <td>0.00</td>\n      <td>0.00</td>\n      <td>-58673.21</td>\n      <td>-58673.21</td>\n      <td>126</td>\n    </tr>\n    <tr>\n      <th>...</th>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n    </tr>\n    <tr>\n      <th>9520</th>\n      <td>NaN</td>\n      <td>10.0</td>\n      <td>49.60</td>\n      <td>59.60</td>\n      <td>30.00</td>\n      <td>89.60</td>\n      <td>1</td>\n    </tr>\n    <tr>\n      <th>9521</th>\n      <td>NaN</td>\n      <td>4.0</td>\n      <td>35.46</td>\n      <td>39.46</td>\n      <td>26.39</td>\n      <td>65.85</td>\n      <td>3</td>\n    </tr>\n    <tr>\n      <th>9522</th>\n      <td>NaN</td>\n      <td>0.0</td>\n      <td>0.00</td>\n      <td>0.00</td>\n      <td>-33061.64</td>\n      <td>-33061.64</td>\n      <td>169</td>\n    </tr>\n    <tr>\n      <th>9523</th>\n      <td>NaN</td>\n      <td>30.0</td>\n      <td>36.00</td>\n      <td>66.00</td>\n      <td>28.70</td>\n      <td>94.70</td>\n      <td>2</td>\n    </tr>\n    <tr>\n      <th>9524</th>\n      <td>NaN</td>\n      <td>7.0</td>\n      <td>58.80</td>\n      <td>65.80</td>\n      <td>29.96</td>\n      <td>95.76</td>\n      <td>1</td>\n    </tr>\n  </tbody>\n</table>\n<p>9525 rows × 7 columns</p>\n</div>"
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "vt = VarianceThreshold(threshold=5)\n",
    "x = data.iloc[:,10:17]\n",
    "transferData = vt.fit_transform(x)\n",
    "\n",
    "x\n"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-12-21T13:29:59.382439800Z",
     "start_time": "2023-12-21T13:29:59.318695900Z"
    }
   },
   "id": "b042c1289efe01b"
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "outputs": [
    {
     "data": {
      "text/plain": "array([[ 1.480000e+01,  3.500000e+01,  4.980000e+01,  3.000000e+01,\n         7.980000e+01,  1.000000e+00],\n       [ 0.000000e+00,  0.000000e+00,  0.000000e+00, -1.153052e+04,\n        -1.153052e+04,  7.500000e+01],\n       [ 0.000000e+00,  0.000000e+00,  0.000000e+00, -7.274370e+03,\n        -7.274370e+03,  1.070000e+02],\n       ...,\n       [ 0.000000e+00,  0.000000e+00,  0.000000e+00, -3.306164e+04,\n        -3.306164e+04,  1.690000e+02],\n       [ 3.000000e+01,  3.600000e+01,  6.600000e+01,  2.870000e+01,\n         9.470000e+01,  2.000000e+00],\n       [ 7.000000e+00,  5.880000e+01,  6.580000e+01,  2.996000e+01,\n         9.576000e+01,  1.000000e+00]])"
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "transferData"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-12-21T13:30:08.800945Z",
     "start_time": "2023-12-21T13:30:08.788606300Z"
    }
   },
   "id": "bae2a6853cd5a358"
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
